use strict;
use utf8;

binmode(STDIN, ":encoding(utf-8)");
binmode(STDOUT, ":encoding(utf-8)");

$/ = "<\/page>";

while (<STDIN>) {
  if ($_ =~ /<redirect\s*\/>/) {
    my ($title, $id, $text);
    $title = $1 if ($_ =~ /<title>([^<]+)<\/title>/);
    $title =~ s/[\"\']//g;
    $id = $1 if ($_ =~ /<id>(\d+)<\/id>/);
    $text = $1 if ($_ =~ /<text[^>]*>([^<]+)<\/text>/);
    print join("\t", ($id, $title, $text)) . "\n";
  }
}
